﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using MOJsdk;
using System.Collections.ObjectModel;

namespace MOJ
{
    /// <summary>
    /// Interaction logic for Control_SelectIndex.xaml
    /// </summary>
    public partial class Control_SelectIndex : UserControl
    {
        private int _max;
        private ObservableCollection<IndexNumbers> _index;

        public Control_SelectIndex(int max)
        {
            InitializeComponent();
            _max = max;
            INI();
        }

        #region Inicialization
        private void INI()
        {
            INIEvents();
            INIStyle();

            if (_max < 1)
                OnIndexSelected(1);

            _index = new ObservableCollection<IndexNumbers>();
            for (int i = 1; i <= _max; i++)
                _index.Add(new IndexNumbers(i));

            _listView.ItemsSource = _index;
        }

        private void INIEvents()
        {
            OnIndexSelected += delegate { };

            _listView.SelectionChanged += SelectionChanged;
        }
        private void INIStyle()
        {
            _Grid.ApplyStyle("0101101");
            _listView.ApplyStyle("0101102");
        }
        #endregion

        private void SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int x = _listView.SelectedIndex;
            if (x == -1) return;

            OnIndexSelected(x + 1);
        }

        public delegate void IndexSelected(int Index);
        public event IndexSelected OnIndexSelected;
    }

    public class IndexNumbers
    {
        public IndexNumbers(int i)
        { Index = i; }

        public int Index
        { get; set; }
    }
}
